home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2001 January / january_2001.iso / intercd / root / ^4Developers / VB / visbasdb / VBDB / VBDB Code / VB6 Code / Class 6 / Example6-8AD.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-09-17  |  10.6 KB  |  360 lines

  1. VERSION 5.00
  2. Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
  3. Begin VB.Form frmAuthors 
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Authors"
  6.    ClientHeight    =   3060
  7.    ClientLeft      =   45
  8.    ClientTop       =   330
  9.    ClientWidth     =   4680
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.    MinButton       =   0   'False
  13.    ScaleHeight     =   3060
  14.    ScaleWidth      =   4680
  15.    StartUpPosition =   3  'Windows Default
  16.    Begin VB.CommandButton cmdHelp 
  17.       Caption         =   "&Help"
  18.       Height          =   375
  19.       Left            =   3240
  20.       TabIndex        =   14
  21.       TabStop         =   0   'False
  22.       Top             =   2640
  23.       Width           =   1215
  24.    End
  25.    Begin VB.CommandButton cmdDone 
  26.       Caption         =   "Do&ne"
  27.       Height          =   375
  28.       Left            =   3240
  29.       TabIndex        =   13
  30.       TabStop         =   0   'False
  31.       Top             =   2160
  32.       Width           =   1215
  33.    End
  34.    Begin VB.CommandButton cmdDelete 
  35.       Caption         =   "&Delete"
  36.       Height          =   375
  37.       Left            =   1680
  38.       TabIndex        =   12
  39.       TabStop         =   0   'False
  40.       Top             =   2160
  41.       Width           =   1215
  42.    End
  43.    Begin VB.CommandButton cmdEdit 
  44.       Caption         =   "&Edit"
  45.       Height          =   375
  46.       Left            =   120
  47.       TabIndex        =   11
  48.       TabStop         =   0   'False
  49.       Top             =   1680
  50.       Width           =   1215
  51.    End
  52.    Begin VB.CommandButton cmdCancel 
  53.       Caption         =   "&Cancel"
  54.       Height          =   375
  55.       Left            =   3240
  56.       TabIndex        =   10
  57.       TabStop         =   0   'False
  58.       Top             =   1680
  59.       Width           =   1215
  60.    End
  61.    Begin VB.CommandButton cmdSave 
  62.       Caption         =   "&Save"
  63.       Height          =   375
  64.       Left            =   1680
  65.       TabIndex        =   9
  66.       TabStop         =   0   'False
  67.       Top             =   1680
  68.       Width           =   1215
  69.    End
  70.    Begin VB.CommandButton cmdAddNew 
  71.       Caption         =   "&Add New"
  72.       Height          =   375
  73.       Left            =   120
  74.       TabIndex        =   8
  75.       TabStop         =   0   'False
  76.       Top             =   2160
  77.       Width           =   1215
  78.    End
  79.    Begin VB.CommandButton cmdNext 
  80.       Caption         =   "Next =>"
  81.       Height          =   255
  82.       Left            =   2520
  83.       TabIndex        =   7
  84.       TabStop         =   0   'False
  85.       Top             =   1320
  86.       Width           =   1215
  87.    End
  88.    Begin VB.CommandButton cmdPrevious 
  89.       Caption         =   "<= Previous"
  90.       Height          =   255
  91.       Left            =   1080
  92.       TabIndex        =   6
  93.       TabStop         =   0   'False
  94.       Top             =   1320
  95.       Width           =   1215
  96.    End
  97.    Begin VB.TextBox txtYearBorn 
  98.       DataField       =   "Year Born"
  99.       DataSource      =   "datAuthors"
  100.       Height          =   285
  101.       Left            =   1200
  102.       Locked          =   -1  'True
  103.       MaxLength       =   4
  104.       TabIndex        =   2
  105.       Text            =   "Text"
  106.       Top             =   840
  107.       Width           =   1215
  108.    End
  109.    Begin VB.TextBox txtAuthor 
  110.       DataField       =   "Author"
  111.       DataSource      =   "datAuthors"
  112.       Height          =   285
  113.       Left            =   1200
  114.       Locked          =   -1  'True
  115.       TabIndex        =   1
  116.       Text            =   "Text2"
  117.       Top             =   480
  118.       Width           =   3375
  119.    End
  120.    Begin VB.TextBox txtAuthorID 
  121.       DataField       =   "Au_ID"
  122.       DataSource      =   "datAuthors"
  123.       Height          =   285
  124.       Left            =   1200
  125.       Locked          =   -1  'True
  126.       TabIndex        =   3
  127.       TabStop         =   0   'False
  128.       Text            =   "Text1"
  129.       Top             =   120
  130.       Width           =   1215
  131.    End
  132.    Begin MSAdodcLib.Adodc datAuthors 
  133.       Height          =   330
  134.       Left            =   2520
  135.       Top             =   120
  136.       Visible         =   0   'False
  137.       Width           =   2055
  138.       _ExtentX        =   3625
  139.       _ExtentY        =   582
  140.       ConnectMode     =   0
  141.       CursorLocation  =   3
  142.       IsolationLevel  =   -1
  143.       ConnectionTimeout=   15
  144.       CommandTimeout  =   30
  145.       CursorType      =   3
  146.       LockType        =   3
  147.       CommandType     =   1
  148.       CursorOptions   =   0
  149.       CacheSize       =   50
  150.       MaxRecords      =   0
  151.       BOFAction       =   0
  152.       EOFAction       =   0
  153.       ConnectStringType=   1
  154.       Appearance      =   1
  155.       BackColor       =   -2147483643
  156.       ForeColor       =   -2147483640
  157.       Orientation     =   0
  158.       Enabled         =   -1
  159.       Connect         =   "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=C:\VBDB\Working\Biblio.mdb"
  160.       OLEDBString     =   "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=C:\VBDB\Working\Biblio.mdb"
  161.       OLEDBFile       =   ""
  162.       DataSourceName  =   ""
  163.       OtherAttributes =   ""
  164.       UserName        =   ""
  165.       Password        =   ""
  166.       RecordSource    =   "SELECT * FROM Authors ORDER BY Author"
  167.       Caption         =   "Adodc1"
  168.       BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  169.          Name            =   "MS Sans Serif"
  170.          Size            =   8.25
  171.          Charset         =   0
  172.          Weight          =   400
  173.          Underline       =   0   'False
  174.          Italic          =   0   'False
  175.          Strikethrough   =   0   'False
  176.       EndProperty
  177.       _Version        =   393216
  178.    End
  179.    Begin VB.Label Label3 
  180.       Caption         =   "Year Born"
  181.       Height          =   255
  182.       Left            =   120
  183.       TabIndex        =   5
  184.       Top             =   840
  185.       Width           =   1215
  186.    End
  187.    Begin VB.Label Label2 
  188.       Caption         =   "Author Name"
  189.       Height          =   255
  190.       Left            =   120
  191.       TabIndex        =   4
  192.       Top             =   480
  193.       Width           =   1215
  194.    End
  195.    Begin VB.Label Label1 
  196.       Caption         =   "Author ID"
  197.       Height          =   255
  198.       Left            =   120
  199.       TabIndex        =   0
  200.       Top             =   120
  201.       Width           =   1215
  202.    End
  203. Attribute VB_Name = "frmAuthors"
  204. Attribute VB_GlobalNameSpace = False
  205. Attribute VB_Creatable = False
  206. Attribute VB_PredeclaredId = True
  207. Attribute VB_Exposed = False
  208. Option Explicit
  209. Private Declare Function WinHelp Lib "user32" Alias "WinHelpA" (ByVal hwnd As Long, ByVal lpHelpFile As String, ByVal wCommand As Long, ByVal dwData As Long) As Long
  210. Private Const HELP_FINDER = &HB&
  211. Private Sub ValidateData(AllOK As Boolean)
  212. Dim Message As String
  213. Dim InputYear As Integer, CurrentYear As Integer
  214. AllOK = True
  215. Message = ""
  216. 'Check for name
  217. If Len(txtAuthor.Text) = 0 Then
  218.   Message = "You must enter an Author Name." + vbCrLf
  219.   txtAuthor.SetFocus
  220.   AllOK = False
  221. End If
  222. 'Check length and range on Year Born
  223. InputYear = Val(txtYearBorn.Text)
  224. CurrentYear = Val(Format(Now, "yyyy"))
  225. If Len(txtYearBorn.Text) <> 0 Then
  226.   If InputYear > CurrentYear Or InputYear < CurrentYear - 150 Then
  227.     Message = Message + "Year Born must be between" & Str(CurrentYear - 150) & " and" & Str(CurrentYear) & "."
  228.     txtYearBorn.SetFocus
  229.     AllOK = False
  230.   End If
  231. End If
  232. If Not (AllOK) Then
  233.   MsgBox Message, vbOKOnly + vbInformation, "Validation Error"
  234. End If
  235. End Sub
  236. Private Sub cmdAddNew_Click()
  237. On Error GoTo HandleErrors
  238. Call SetState("Add")
  239. Exit Sub
  240. HandleErrors:
  241. Select Case MsgBox(Err.Description, vbCritical + vbAbortRetryIgnore, "Error Number" + Str(Err.Number) + " in " + Err.Source)
  242. Case vbAbort
  243.   Exit Sub
  244. Case vbRetry
  245.   Resume
  246. Case vbIgnore
  247.   Resume Next
  248. End Select
  249. End Sub
  250. Private Sub cmdCancel_Click()
  251. Call SetState("View")
  252. End Sub
  253. Private Sub cmdDelete_Click()
  254. Dim Response As Integer
  255. On Error GoTo HandleErrors
  256. Response = MsgBox("Are you sure you want to delete this record?", vbYesNo + vbQuestion + vbDefaultButton2, "Delete")
  257. If Response = vbNo Then
  258.   Exit Sub
  259. End If
  260. Exit Sub
  261. HandleErrors:
  262. Select Case MsgBox(Err.Description, vbCritical + vbAbortRetryIgnore, "Error Number" + Str(Err.Number) + " in " + Err.Source)
  263. Case vbAbort
  264.   Exit Sub
  265. Case vbRetry
  266.   Resume
  267. Case vbIgnore
  268.   Resume Next
  269. End Select
  270. End Sub
  271. Private Sub cmdEdit_Click()
  272. Call SetState("Edit")
  273. End Sub
  274. Private Sub cmdHelp_Click()
  275. Dim Rtn As Long
  276. Rtn = WinHelp(frmAuthors.hwnd, App.HelpFile, HELP_FINDER, CLng(0))
  277. End Sub
  278. Private Sub cmdNext_Click()
  279. datAuthors.Recordset.MoveNext
  280. If datAuthors.Recordset.EOF Then
  281.   Beep
  282.   datAuthors.Recordset.MoveLast
  283. End If
  284. End Sub
  285. Private Sub cmdPrevious_Click()
  286. datAuthors.Recordset.MovePrevious
  287. If datAuthors.Recordset.BOF Then
  288.   Beep
  289.   datAuthors.Recordset.MoveFirst
  290. End If
  291. End Sub
  292. Private Sub cmdSave_Click()
  293. Dim Valid As Boolean
  294. Call ValidateData(Valid)
  295. If Not (Valid) Then Exit Sub
  296. On Error GoTo HandleErrors
  297. MsgBox "Record saved.", vbOKOnly + vbInformation, "Save"
  298. Call SetState("View")
  299. Exit Sub
  300. HandleErrors:
  301. Select Case MsgBox(Err.Description, vbCritical + vbAbortRetryIgnore, "Error Number" + Str(Err.Number) + " in " + Err.Source)
  302. Case vbAbort
  303.   Exit Sub
  304. Case vbRetry
  305.   Resume
  306. Case vbIgnore
  307.   Resume Next
  308. End Select
  309. End Sub
  310. Private Sub SetState(AppState As String)
  311. Select Case AppState
  312. Case "View"
  313.   txtAuthorID.BackColor = vbWhite
  314.   txtAuthor.Locked = True
  315.   txtYearBorn.Locked = True
  316.   cmdPrevious.Enabled = True
  317.   cmdNext.Enabled = True
  318.   cmdAddNew.Enabled = True
  319.   cmdSave.Enabled = False
  320.   cmdCancel.Enabled = False
  321.   cmdEdit.Enabled = True
  322.   cmdDelete.Enabled = True
  323.   cmdDone.Enabled = True
  324.   txtAuthor.SetFocus
  325. Case "Add", "Edit"
  326.   txtAuthorID.BackColor = vbRed
  327.   txtAuthor.Locked = False
  328.   txtYearBorn.Locked = False
  329.   cmdPrevious.Enabled = False
  330.   cmdNext.Enabled = False
  331.   cmdAddNew.Enabled = False
  332.   cmdSave.Enabled = True
  333.   cmdCancel.Enabled = True
  334.   cmdEdit.Enabled = False
  335.   cmdDelete.Enabled = False
  336.   cmdDone.Enabled = False
  337.   txtAuthor.SetFocus
  338. End Select
  339. End Sub
  340. Private Sub Form_Activate()
  341. Call SetState("View")
  342. End Sub
  343. Private Sub txtAuthor_KeyPress(KeyAscii As Integer)
  344. If KeyAscii = vbKeyReturn Then
  345.   txtYearBorn.SetFocus
  346.   Exit Sub
  347. End If
  348. End Sub
  349. Private Sub txtYearBorn_KeyPress(KeyAscii As Integer)
  350. If KeyAscii = vbKeyReturn Then
  351.   txtAuthor.SetFocus
  352.   Exit Sub
  353. End If
  354. If (KeyAscii >= Asc("0") And KeyAscii <= Asc("9")) Or KeyAscii = vbKeyBack Then
  355.   Exit Sub
  356.   Beep
  357.   KeyAscii = 0
  358. End If
  359. End Sub
  360.